using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NetObject : MonoBehaviour
{
    public string netId;

    private Vector3 targetPos;
    private Quaternion targetRot;

    private readonly float moveLerpSpeed = 10f;
    private readonly float rotLerpSpeed = 10f;

    private Rigidbody rb;

    void Start()
    {
        rb = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void FixedUpdate()
    {
        SyncData();
    }

    public void SetID(string id) { netId = id; }

    void SyncData()
    {
        if (transform.position.y < -32f)
        {
            rb.MovePosition(new Vector3(0, 1, 0));
            rb.MoveRotation(Quaternion.identity);
            return;
        }

        rb.MovePosition(Vector3.Lerp(rb.position, targetPos, Time.fixedDeltaTime * moveLerpSpeed));
        rb.MoveRotation(Quaternion.Slerp(rb.rotation, targetRot, Time.fixedDeltaTime * rotLerpSpeed));
    }

    public void SetTarTrans(Vector3 pos, Quaternion rot)
    {
        targetPos = pos;
        targetRot = rot;
    }
}
